package com.smartcaliper;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.smartcaliper.base.BaseFragment;
import com.smartcaliper.base.BaseMainActivity;
import com.smartcaliper.fragment.AboutFragment;
import com.smartcaliper.fragment.DeviceFragment;
import com.smartcaliper.fragment.FirstFragment;
import com.smartcaliper.fragment.ProfileFragment;
import com.smartcaliper.fragment.UnitFragment;
import com.smartcaliper.login.LoginActivity;
import com.smartcaliper.view.SlidingMenu;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

@SuppressWarnings("ResourceAsColor")
public class MainActivity extends BaseMainActivity implements BaseFragment.OnFragmentInteractionListener {
    @Bind(R.id.user_head_img)
    ImageView userHeadImg;
    @Bind(R.id.user_name_tv)
    TextView userNameTv;
    @Bind(R.id.measurement_tv)
    TextView measurementTv;
    @Bind(R.id.login_tv)
    TextView loginTv;
    @Bind(R.id.device_tv)
    TextView deviceTv;
    @Bind(R.id.unit_tv)
    TextView unitTv;
    @Bind(R.id.about_tv)
    TextView aboutTv;
    @Bind(R.id.video_tv)
    TextView videoTv;
    @Bind(R.id.my_content)
    FrameLayout myContent;
    @Bind(R.id.id_menu)
    SlidingMenu idMenu;
    @Bind(R.id.menu_btn)
    ImageView menuBtn;
    @Bind(R.id.saoyisao)
    ImageView saoyisao;
    @Bind(R.id.title)
    TextView titleTV;
    @Bind(R.id.content_layout)
    LinearLayout content_layout;
    FragmentManager fragmentManager;
    AboutFragment aboutFragment;
    FirstFragment firstFragment;
    ProfileFragment profileFragment;
    UnitFragment unitFragment;
    DeviceFragment deviceFragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        applyTransSystemBar();
        fragmentManager = getSupportFragmentManager();
        firstFragment = new FirstFragment();
        fragmentManager.beginTransaction()
                .add(R.id.my_content, firstFragment)
                .commit();
    }

    @OnClick({R.id.user_head_img, R.id.measurement_tv, R.id.login_tv, R.id.device_tv, R.id.unit_tv, R.id.about_tv, R.id.video_tv,R.id.menu_btn, R.id.saoyisao})
    public void onClick(View view) {
        Intent intent = null;
        switch (view.getId()) {
            case R.id.user_head_img:
                if(profileFragment==null)profileFragment = new ProfileFragment();
                fragmentManager.beginTransaction()
                        .replace(R.id.my_content, profileFragment)
                        .commit();
                titleTV.setVisibility(View.VISIBLE);
                titleTV.setText(getString(R.string.profile));
                saoyisao.setVisibility(View.INVISIBLE);
                content_layout.setBackgroundResource(R.drawable.login_background);
                break;
            case R.id.measurement_tv:
                if(firstFragment==null)firstFragment = new FirstFragment();
                fragmentManager.beginTransaction()
                        .replace(R.id.my_content, firstFragment)
                        .commit();
                titleTV.setVisibility(View.INVISIBLE);
                saoyisao.setVisibility(View.VISIBLE);
                content_layout.setBackgroundResource(R.drawable.login_background);
                break;
            case R.id.login_tv:
                intent = new Intent(this, LoginActivity.class);
                startActivity(intent);
                break;
            case R.id.device_tv:

                if(deviceFragment==null)deviceFragment = new DeviceFragment();
                fragmentManager.beginTransaction()
                        .replace(R.id.my_content, deviceFragment)
                        .commit();
                titleTV.setVisibility(View.VISIBLE);
                titleTV.setText(getString(R.string.serch_device));
                saoyisao.setVisibility(View.INVISIBLE);
                content_layout.setBackgroundResource(R.drawable.deviceBg);
                applySystemBarColor(R.color.colorDeviceBg);
                break;
            case R.id.unit_tv:
                if(unitFragment==null)unitFragment = new UnitFragment();
                fragmentManager.beginTransaction()
                        .replace(R.id.my_content, unitFragment)
                        .commit();
                titleTV.setVisibility(View.VISIBLE);
                titleTV.setText(getString(R.string.unit_switch));
                saoyisao.setVisibility(View.INVISIBLE);
                content_layout.setBackgroundResource(R.drawable.login_background);
                break;
            case R.id.about_tv:
                if(aboutFragment==null)aboutFragment = new AboutFragment();
                fragmentManager.beginTransaction()
                        .replace(R.id.my_content, aboutFragment)
                        .commit();
                content_layout.setBackgroundResource(R.drawable.login_background);
                break;
            case R.id.video_tv:
                break;
            case R.id.menu_btn:
                idMenu.toggle();
                break;
            case R.id.saoyisao:

                break;
        }
        idMenu.toggle();
    }

    @Override
    public void onFragmentInteraction(int type) {

    }


}
